import { changeLocale as changeLocaleI18n } from '@/locales'
import { store } from '..'

export const useLocaleStore = defineStore('locale', () => {
  // 缓存中的语言
  const locale = useAppLocalStorage<string>('LOCALE', navigator.language)

  const changeLocale = async (newLocale: string) => {
    locale.value = newLocale
    await changeLocaleI18n(locale.value)
  }
  return {
    locale,
    changeLocale,
  }
})

export const useLocaleStoreWithOut = () => {
  return useLocaleStore(store)
}
